/**
 * Created by maxiaoqiang on 2018/4/9.
 */

import axios from 'axios';
import {local} from "util/MyUtil";
const config = {
    baseURL: "/api/",
    timeout: 10000,
    headers: {
        'Accept': 'application/json',
        'Content-Type': 'application/json',
        'Cache-Control': 'cache',
        "userId":local.get("userInfo").id
    },
    // 跨域请求，是否带上认证信息
    withCredentials: true,
    responseType: 'json'
};
const HttpClient = axios.create(config);

HttpClient.interceptors.request.use((config) => {

        // 若是有做鉴权token , 就给头部带上token
        return config;

    }, (error) => {
        // 当请求错误时
        Promise.reject(error)
    }
);

HttpClient.interceptors.response.use((resp) => {
        return resp;
    },
    (error) => {
        return Promise.reject(error)
    }
);

export {HttpClient};